<template>
	<view>
		<u-form :model="form" ref="uform" :rules="rules" label-width="240rpx" :error-type="errorType">
		  <u-form-item :label="item.title" prop="value" :required="item.must">
			  <u-checkbox-group @change="checkboxChange">
				<u-checkbox
					v-model="val.value"
					v-for="(val, index) in item.selectData" :key="index" 
					:name="val.id"
				>
					{{val.label}}
				</u-checkbox>
			</u-checkbox-group>
		  </u-form-item>
		</u-form>
	</view>
</template>

<script>
export default {
  props: ["item", "number"],
  data() {
    return {
	  errorType: ['message'],
      form: {
		  value: []
	  },
      rules: {
        value: [
          { required: this.item.must, type: 'array', message: this.item.msg, trigger: 'change' },
        ],
      }
    };
  },
  methods: {
	  checkboxChange(e) {
		  this.form.value = e
		  this.$emit("changeComponent", {
		    number: this.number,
		    type: this.item.type,
		    value: this.form.value,
		  });
		},
  },
  mounted() {
		this.form = {
		  ...this.form,
		  ...this.item,
		};
		this.$refs.uform.setRules(this.rules);
	}
};
</script>

<style>
</style>
